#include "process_pool.h"
//#define FILENAME "file"
//#define FILENAME "The_Holy_Bible.txt"
#define FILENAME "114.day35-进程池5.mp4"
void sigfunc(int signum)
{
    printf("Get signum %d\n",signum);
}
int trans_file(int newfd)
{
    signal(SIGPIPE,sigfunc);
    train_t dt;//dataTrain
    //发送文件名
    dt.dataLen=strlen(FILENAME);
    strcpy(dt.buf,FILENAME);
    send(newfd,&dt,sizeof(dt.dataLen)+dt.dataLen,0);
    //发送文件大小
    struct stat buf;
    stat(FILENAME,&buf);
    dt.dataLen=sizeof(buf.st_size);
    memcpy(dt.buf,&buf.st_size,dt.dataLen);
    send(newfd,&dt,sizeof(dt.dataLen)+dt.dataLen,0);
    //发送文件
    int fd=open(FILENAME,O_RDWR);
    char *pstart=(char*)mmap(NULL,buf.st_size,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);
    ERROR_CHECK(pstart,(char*)-1,"mmap");
    send(newfd,pstart,buf.st_size,0);
    munmap(pstart,buf.st_size);
    //发送结束信号
    //dt.dataLen=0;
    //send(newfd,&dt,4,0);
    return 0;
}

